package com.project.util;

import com.project.frame.GameStartFrame;
import com.project.role.GirlBullet;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class KeyPress implements KeyListener {
    /**
     * 是否按上
     */
    public static boolean isUp;
    /**
     * 是否按下
     */
    public static boolean isDown;
    /**
     * 是否按左
     */
    public static boolean isLeft;
    /**
     * 是否按右
     */
    public static boolean isRight;

    /**
     * 是否攻击
     */

    public static boolean isAttack;


    @Override
    public void keyTyped(KeyEvent e) {
    }


    //键盘按下触发
    @Override
    public void keyPressed(KeyEvent e) {
        //得到键盘码
        int code = e.getKeyCode();

        if (code == KeyEvent.VK_W) {
            isUp = true;
        }
        if (code == KeyEvent.VK_S) {
            isDown = true;
        }
        if (code == KeyEvent.VK_D) {
            isRight = true;
        }
        if (code == KeyEvent.VK_A) {
            isLeft = true;
        }

        if ( code == KeyEvent.VK_J){
            isAttack = true;
        }

    }

    //键盘弹起触发
    @Override
    public void keyReleased(KeyEvent e) {
        //得到键盘码
        int code = e.getKeyCode();

        if (code == KeyEvent.VK_J) {
            isAttack = false;
        }

        if (code == KeyEvent.VK_W) {
            isUp = false;
        }
        if (code == KeyEvent.VK_S) {
            isDown = false;
        }
        if (code == KeyEvent.VK_D) {
            isRight = false;
        }
        if (code == KeyEvent.VK_A) {
            isLeft = false;
        }

    }
}
